package com.panopset.gui.container;

import static com.panopset.Util.*;

/**
 *
 * Panopset long field.
 *
 * @author Karl Dinwiddie
 */
public final class PanLongField extends PanNumericOnlyField {

    /**
     * Long field message.
     */
    private static final String LONG_FIELD_MESSAGE = x("Please"
            + " enter a long value, no decimal places.");

    /**
     * @return long value.
     */
    public Long getLongValue() {
        return Long.parseLong(getValue());
    }

    /**
     * @param cols
     *            Columns.
     * @param borderTitle
     *            Border title.
     * @param toolTipText
     *            Tool tip text.
     * @param defaultValue
     *            Default value.
     */
    public PanLongField(final int cols, final String borderTitle,
            final String toolTipText, final String defaultValue) {
        super(cols, borderTitle, toolTipText, defaultValue);
        addValidator(new Validator() {

            @Override
            public String validate(final String value) {
                if (value == null) {
                    return LONG_FIELD_MESSAGE;
                }
                try {
                    Long.parseLong(value);
                } catch (NumberFormatException ex) {
                    return LONG_FIELD_MESSAGE;
                }
                return null;
            }
        });
    }

}
